package com.itheima06;

import java.util.Collections;
import java.util.TreeSet;

/**
 * @author Xiao
 * @date 2021/7/25
 */
public class StudentTest01 {
    /**
     * TreeSet练习：
     *      存储学生对象，并遍历
     */
    public static void main(String[] args) {
        Student1 stu1 = new Student1("阿良1号", 24);
        Student1 stu2 = new Student1("阿良2号", 18);
        Student1 stu3 = new Student1("阿良3号", 21);
        TreeSet<Student1> ts = new TreeSet<>();
        Collections.addAll(ts, stu1, stu2, stu3);
        for (Student1 stu : ts) {
            System.out.println(stu);
        }
        /*Student stu1 = new Student("阿良1号", 24);
        Student stu2 = new Student("阿良2号", 18);
        Student stu3 = new Student("阿良3号", 21);
        TreeSet<Student> ts = new TreeSet<>();
        //ClassCastException
        Collections.addAll(ts, stu1, stu2, stu3);
        for (Student stu : ts) {
            System.out.println(stu);
        }*/
    }
}
